﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.DirectX.Direct3D;
using System.Threading;

namespace MediaCenter.Controls
{
    public partial class LCARS_4eck : LCARS_Control
    {
        private ElboType _TextAligment;
        private Device D3X_Dev;
        private Microsoft.DirectX.Direct3D.Font dx_text;

        public ElboType TextAligment
        {
            get
            {
                return _TextAligment;
            }
            set
            {
                _TextAligment = value;
            }
        }
        
        public LCARS_4eck()
        {
            InitializeComponent();
            _TextAligment = ElboType.oben_links;
        }



        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.DesignMode || this.PartmentForm.RenderMode == RenderMode.GDI)
            {
                e.Graphics.FillRectangle(new SolidBrush(this.BackColor), new Rectangle(0, 0, this.Width, this.Height));
                int txtbreite = TextRenderer.MeasureText(this.Text, this.Font).Width;
                int txthöhe = TextRenderer.MeasureText(this.Text, this.Font).Height;
                Brush strB = new SolidBrush(this.ForeColor);
                switch (_TextAligment)
                {
                    case ElboType.oben_links:
                        e.Graphics.DrawString(this.Text, this.Font, strB, 5, 5);
                        break;
                    case ElboType.oben_rechts:
                        e.Graphics.DrawString(this.Text, this.Font, strB, this.Width - txtbreite, 5);
                        break;
                    case ElboType.unten_links:
                        e.Graphics.DrawString(this.Text, this.Font, strB, 5, this.Height - txthöhe - 5);
                        break;
                    case ElboType.unten_rechts:
                        e.Graphics.DrawString(this.Text, this.Font, strB, this.Width - txtbreite - 5, this.Height - txthöhe - 5);
                        break;
                }
            }    
        }

        private void draw_4Eck(Rectangle data)
        {

            CustomVertex.TransformedColored[] _3Eck = new CustomVertex.TransformedColored[3];
            _3Eck[0].Position = new Microsoft.DirectX.Vector4(data.X, data.Y, 0, 2.0f); ;
            _3Eck[1].Position = new Microsoft.DirectX.Vector4(data.X + data.Width, data.Y, 0, 2.0f); ;
            _3Eck[2].Position = new Microsoft.DirectX.Vector4(data.X, data.Y + data.Height, 0, 2.0f); ;


            _3Eck[0].Color = this.BackColor.ToArgb();
            _3Eck[1].Color = this.BackColor.ToArgb();
            _3Eck[2].Color = this.BackColor.ToArgb();

            this.D3X_Dev.VertexFormat = CustomVertex.TransformedColored.Format;
            this.D3X_Dev.DrawUserPrimitives(PrimitiveType.TriangleList, 1, _3Eck);

            _3Eck = new CustomVertex.TransformedColored[3];
            _3Eck[0].Position = new Microsoft.DirectX.Vector4(data.X, data.Y + data.Height, 0, 2.0f); ;
            _3Eck[1].Position = new Microsoft.DirectX.Vector4(data.X + data.Width, data.Y, 0, 2.0f); ;
            _3Eck[2].Position = new Microsoft.DirectX.Vector4(data.X + data.Width, data.Y + data.Height, 0, 2.0f); ;


            _3Eck[0].Color = this.BackColor.ToArgb();
            _3Eck[1].Color = this.BackColor.ToArgb();
            _3Eck[2].Color = this.BackColor.ToArgb();

            this.D3X_Dev.VertexFormat = CustomVertex.TransformedColored.Format;
            this.D3X_Dev.DrawUserPrimitives(PrimitiveType.TriangleList, 1, _3Eck);
        }

        public override void Render()
        {
            base.Render();
            if (!this.DesignMode)
            {
                D3X_Dev = this.PartmentForm.D3X_Dev;
                dx_text = new Microsoft.DirectX.Direct3D.Font(D3X_Dev, this.Font);

                draw_4Eck(new Rectangle(this.Left, this.Top, this.Width, this.Height));


                dx_text = null;
            }
        }
    }
}
